/*
 * 
 */

package com.memorytech.starchive;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.widget.VideoView;

import com.memorytech.starchive.interfaceclass.OnVideoViewListener;

public class CustomVideo extends VideoView implements OnGestureListener {
    /*
     * (non-Javadoc)
     * @see android.widget.VideoView#onTouchEvent(android.view.MotionEvent)
     */
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        // TODO Auto-generated method stub
        gd.onTouchEvent(ev);
        return true;
    }

    // creates a Gesture Detector
    private GestureDetector gd;

    /** The video view listener. */
    private OnVideoViewListener videoViewListener;

    public CustomVideo(Context context, AttributeSet attrs) {
        super(context, attrs);
        // creating new gesture detector
        gd = new GestureDetector(this);

        // set the on Double tap listener
        gd.setOnDoubleTapListener(new OnDoubleTapListener()
        {

            @Override
            public boolean onDoubleTap(MotionEvent e) {
                // TODO Auto-generated method stub
                videoViewListener.onDoubleTouchListener();
                return true;
            }

            @Override
            public boolean onDoubleTapEvent(MotionEvent e) {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                // TODO Auto-generated method stub
                videoViewListener.onSingleTouchListener();
                return true;
            }

        });
    }

    public CustomVideo(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        // initialize the Gesture Detector

    }

    @Override
    public boolean onDown(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    /**
     * @return the videoViewListener
     */
    public OnVideoViewListener getVideoViewListener() {
        return videoViewListener;
    }

    /**
     * @param videoViewListener the videoViewListener to set
     */
    public void setVideoViewListener(OnVideoViewListener videoViewListener) {
        this.videoViewListener = videoViewListener;
    }

}
